package ru.alt22.visor.php.core;

import java.net.URL;

import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.osgi.framework.BundleContext;

public class PDToolsCorePlugin extends AbstractUIPlugin {

	public static final String LOG_TITLE = "PDTools plug-in internal error";
	public static final String PLUGIN_ID = "ru.alt22.visor.php.core";
	public static final int INTERNAL_ERROR = 10001;

	private static PDToolsCorePlugin plugin;

	public PDToolsCorePlugin() {
		plugin = this;
	}

	public void start(BundleContext context) throws Exception {
		super.start(context);
	}

	public void stop(BundleContext context) throws Exception {
		plugin = null;
		super.stop(context);
	}

	public static PDToolsCorePlugin getDefault() {
		return plugin;
	}

	public static URL getResource(String resource) {
		return getResource(PLUGIN_ID, resource);
	}
	
	public static URL getResource(String pluginId, String resource) {
		return Platform.getBundle(pluginId).getResource(resource);
	}

	public static String getStringPreference(String name) {
		return getDefault().getPreferenceStore().getString(name);
	}

	public static void log(String message) {
		log(new Status(IStatus.ERROR, PLUGIN_ID, INTERNAL_ERROR, message, null));
	}

	public static void log(IStatus status) {
		getDefault().getLog().log(status);
	}

	public static void log(Throwable e) {
		log(new Status(IStatus.ERROR, PLUGIN_ID, INTERNAL_ERROR, LOG_TITLE, e));
	}

	public static IWorkspace getWorkspace() {
		return ResourcesPlugin.getWorkspace();
	}

}